package com.huan.social.baidu.connect;

import com.huan.social.baidu.api.Baidu;
import com.huan.social.baidu.api.BaiduUserInfo;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;

/**
 * 百度的 api 适配器
 *
 * @author huan.fu
 * @date 2018/9/27 - 17:10
 */
public class BaiduAdapter implements ApiAdapter<Baidu> {
	@Override
	public boolean test(Baidu api) {
		return true;
	}

	@Override
	public void setConnectionValues(Baidu api, ConnectionValues values) {
		BaiduUserInfo userInfo = api.getUserInfo();
		values.setDisplayName(userInfo.getRealName() == null ? userInfo.getUsername() : userInfo.getRealName());
		values.setImageUrl(String.format("http://tb.himg.baidu.com/sys/portrait/item/%s", userInfo.getPortrait()));
		values.setProfileUrl(null);
		values.setProviderUserId(userInfo.getUserId());
	}

	@Override
	public UserProfile fetchUserProfile(Baidu api) {
		return null;
	}

	@Override
	public void updateStatus(Baidu api, String message) {

	}
}
